package com.study.testSpringBoot.login;

import java.time.Duration;
import java.time.Instant;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @author wc_phz
 * @ClassName LoginUtil
 * @Description: [ ]
 * @date 2020/3/31 17:31
 */
public class LoginUtil {

    private static ConcurrentHashMap<Integer, Instant> login = new ConcurrentHashMap<>();

    public static void addLoginRecord(String username, String password){
        int i = (username + password).hashCode();
        login.put(i, Instant.now());
    }

    public static boolean getLoginRecord(String username, String password){
        int i = (username + password).hashCode();
        Instant instant = login.get(i);
        System.out.println("插入时间："+instant);
        if(instant != null){
            Instant end = Instant.now();
            System.out.println("当前时间："+end);
            long l = Duration.between(instant, end).getSeconds();
            System.out.println("间隔时间" + l);
            if(l < 3){
                return false;
            }
        }
        return true;
    }
}
